#pragma once

template<class iterator, class Ref, class Ptr>
class ReverseIterator
{
	typedef ReverseIterator<iterator, Ref, Ptr> self;
public:
	iterator cur;

	ReverseIterator(iterator it)
		:cur(it)
	{}

	self& operator++()
	{
		--cur;
		return *this;
	}

	self& operator++(int)
	{
		self tmp(cur);
		--cur;
		return tmp;
	}

	self& operator--()
	{
		++cur;
		return *this;
	}

	self& operator--(int)
	{
		self tmp(cur);
		++cur;
		return tmp;
	}

	Ref operator*()
	{
		iterator tmp = cur;
		--tmp;
		return *tmp;
	}

	Ptr operator->()
	{
		return &(operator*());
	}

	bool operator==(const self& s)
	{
		return cur == s.cur;
	}

	bool operator!=(const self& s)
	{
		return cur != s.cur;
	}
};